<template>
  <d2-container>
    <template>
      <el-button type="primary" size="small" @click="open()">新增管理员</el-button>
      <el-table
        :data="admins"
        border
        :default-sort="{prop: 'adminId', order: 'Ascending'}"
        style="width: 100%; margin-top: 10px "
      >
        <el-table-column fixed prop="adminId" label="用户ID" width="100"></el-table-column>
        <el-table-column prop="adminName" label="管理员名称" width="150"></el-table-column>
        <el-table-column prop="level" label="级别" width="120"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button size="mini" type="danger" @click="handleDelete()">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </d2-container>
</template>

<script>
import { getAdminPage, addAdmin } from '@api/manager'
export default {
  data () {
    return {
      totalCount: 0,
      pageSize: 10,
      pageNum: 1,
      keyword: '',
      admins: []
    }
  },
  mounted: function () {
    this.getAdminPageRequest()
  },
  methods: {
    getAdminPageRequest: function () {
      getAdminPage({
        pageSize: this.pageSize,
        pageNum: this.pageNum,
        keyword: this.keyword
      })
        .then(res => {
          this.admins = res.admins
          console.log(res.admins)
        })
        .catch(err => {
          console.log(err)
        })
    },
    //  新增管理员
    addAdminRequest: function () {
      addAdmin()
        .then(res => {
          console.log(res)
        })
        .catch(err => {
          console.log(err)
        })
    },
    open: function () {
    },
    // 删除操作
    handleDelete: function () {
      console.log(1, 2)
    }
  }
}
</script>
